<?php
namespace app\app\controller\v1;

use think\Db;
use think\Request;
use app\app\util\OnlineUtils;

class MessageController extends BaseController{

    /**
     * 显示资源列表
     * 别人给我的留言
     * @return \think\Response
     */
    public function index()
    {
        $user_id = OnlineUtils::getUserIdBySid();
        if(input('get.id') && input('get.id') >0){
            $page = config('PAGE_NUM').input('get.id');
        }else{
            $page = 0;
        }
        //查询数据
        $message = Db::query('select a.id,a.user_id,a.content,b.username,b.portrait from hmp_messages a left join hmp_users b on a.user_id=b.id where a.be_user_id='.$user_id.' and b.status=1 and a.status=1 order by a.id desc limit '.$page.',10');
        if($message){

        }else{
            $message = [];
        }
        return hmp(200,'success',['data'=>$message]);
    }

    /**
     * 显示创建资源表单页.
     *
     * @return \think\Response
     */
    public function create()
    {

    }

    /**
     * 保存新建的资源
     * 点赞
     * @param  \think\Request  $request
     * @return \think\Response
     */
    public function save()
    {
        $user_id = OnlineUtils::getUserIdBySid();
        $message['user_id'] = $user_id;
        $message['be_user_id'] = input('post.user_id');
        $message['content'] = input('post.content');
        $id = Db::name('messages')->insertGetId($message);
        if($id){
            return hmp(200,'success');
        }else{
            return hmp(402,'fail');
        }
    }

    /**
     * 显示指定的资源
     *
     * @param  int  $id
     * @return \think\Response
     */
    public function read($id)
    {

    }

    /**
     * 显示编辑资源表单页.
     *
     * @param  int  $id
     * @return \think\Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * 保存更新的资源
     *
     * @param  \think\Request  $request
     * @param  int  $id
     * @return \think\Response
     */
    public function update($id)
    {

    }

    /**
     * 删除指定资源
     *
     * @param  int  $id
     * @return \think\Response
     */
    public function delete($id)
    {

    }
}